/**
 * @brief 		motor_QDrive_PM4310.h库文件
 * @detail
 * @author 	    Haoqi Liu
 * @date        25-5-2
 * @version 	V1.0.0
 * @note 		
 * @warning	    
 * @par 		历史版本
                V1.0.0创建于25-5-2
 * */

#ifndef MOTOR_QDRIVE_PM4310_H
#define MOTOR_QDRIVE_PM4310_H

#include "numbers"
#include "motor_base.h"
#include "fdcan.h"

#define CMD_NOP         0x00
#define CMD_ENABLE      0x01
#define CMD_DISABLE     0x02
#define CMD_BASE_CALIB  0x03
#define CMD_COGG_CALIB  0x04
#define CMD_MOTION_CTRL 0x05
#define CMD_SET_ID      0x06

#define MOTION_MODE_CUR 0x00
#define MOTION_MODE_SPD 0x01
#define MOTION_MODE_ANG 0x02

using namespace std;

class pm4310 final : public bldc_motor {
public:
    enum CtrlMode {
        CtrlMode_Voltage = 0,
        CtrlMode_Current = 1,
    };

    pm4310() = delete;

    pm4310(FDCAN_HandleTypeDef *hfdcan, uint32_t id) : hfdcan(hfdcan) {
        this->id = id;
    }

    CtrlMode ctrl_mode{CtrlMode_Current};

    bool initialize() override;
    bool enable() override;
    bool disable() override;
    bool start() override;
    bool stop() override;
    void update(uint8_t *data);
    void set_torque(float torque) override;
    void set_speed(float speed) override;
    void set_angle(float angle) override;
    void set_id(uint8_t id);

private:
    FDCAN_HandleTypeDef *hfdcan; // CAN句柄
    uint8_t TxBuffer[8]{};       // 发送缓冲区域
    void send_can_message() const;
};

#endif //MOTOR_QDRIVE_PM4310_H
